package com.ccut.xunfeiSpringboot.controller;/*
 * ClassName: QuestionController
 * Package: com.ccut.xunfeiSpringboot.controller
 * Description:
 * @Author 刘千湫
 * @Create 2025/7/12 10:24
 * @Version 1.0
 */
import com.ccut.xunfeiSpringboot.common.AjaxResult;
import com.ccut.xunfeiSpringboot.entity.Question;
import com.ccut.xunfeiSpringboot.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @GetMapping("/all")
    public AjaxResult getAllQuestions() {
        List<Question> questions = questionService.getAllQuestions();
        return AjaxResult.success(questions);
    }

    @GetMapping("/{id}")
    public AjaxResult getQuestionById(@PathVariable Integer id) {
        Question question = questionService.getQuestionById(id);
        return AjaxResult.success(question);
    }

    @PostMapping("/add")
    public AjaxResult addQuestion(@RequestBody Question question) {
        questionService.addQuestion(question);
        return AjaxResult.success();
    }

    @PutMapping("/update")
    public AjaxResult updateQuestion(@RequestBody Question question) {
        questionService.updateQuestion(question);
        return AjaxResult.success();
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteQuestion(@PathVariable Integer id) {
        questionService.deleteQuestion(id);
        return AjaxResult.success();
    }
    @GetMapping("/page")
    public AjaxResult getQuestionsByPage(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize) {
        List<Question> questions = questionService.getQuestionsByPage(pageNum, pageSize);
        return AjaxResult.success(questions);
    }

}
